package com.chen.lifepic.DataAdapter;

import java.util.Vector;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chen.lifepic.R;
import com.chen.lifepic.utils.APPCommonDef.GirlType;

public class HomeDataAdapter extends BaseAdapter {
	Context mContext = null;
	Vector<Integer> mGirlTypes = null;

	public HomeDataAdapter(Context context) {
		mContext = context;

		mGirlTypes = new Vector<Integer>();
		mGirlTypes.add(GirlType.Girl_Sex_Girl);
		mGirlTypes.add(GirlType.Girl_Network);
		mGirlTypes.add(GirlType.Girl_Cute_Girl);
		mGirlTypes.add(GirlType.Girl_Home_Men);
		mGirlTypes.add(GirlType.Girl_Long_Leg);
	}

	@Override
	public int getCount() {
		if (null == mGirlTypes)
			return 0;
		
		return mGirlTypes.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public int getGirlTypeByPosition(int position) {
		try {
			return mGirlTypes.get(position);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return GirlType.Girl_Cute_Girl;
	}

	public int getGirlTypeStrRes(int type) {
		int resId = R.string.cute_girl;
		switch (type) {
		case GirlType.Girl_Network:
			resId = R.string.network_girl;
			break;
			
		case GirlType.Girl_Cute_Girl:
			resId = R.string.cute_girl;
			break;

		case GirlType.Girl_Home_Men:
			resId = R.string.girl_of_home_men;
			break;

		case GirlType.Girl_Long_Leg:
			resId = R.string.long_leg_girl;
			break;
			
		case GirlType.Girl_Sex_Girl:
			resId = R.string.sex_girl;
			break;
			
		default:
			break;
		}
		return resId;
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		if (null != view && null != view.getTag()
				&& view.getTag() instanceof HomeListItemHolder) {
			// Fill view
		} else {
			view = View.inflate(mContext, R.layout.list_item_home, null);
			HomeListItemHolder holder = new HomeListItemHolder();
			holder.mIVSrc = (ImageView) view.findViewById(R.id.iv_home_item);
			holder.mTvTitle = (TextView) view.findViewById(R.id.tv_home_item);

			view.setTag(holder);
		}

		fillView(view, position);
		return view;
	}

	void fillView(View view, int index) {
		if (null != view && null != view.getTag()
				&& view.getTag() instanceof HomeListItemHolder) {
			HomeListItemHolder holder = (HomeListItemHolder) view.getTag();

			holder.mTvTitle.setText(getGirlTypeStrRes(getGirlTypeByPosition(index)));
		}
	}

	class HomeListItemHolder {
		TextView mTvTitle;
		ImageView mIVSrc;
	}
}
